#include <stdio.h>

int n;

int partition(int arr[],int l,int r){
  int p = l;
  int temp;

  //SWAP (A[p],A[r])
  // int temp = arr[p];
  // arr[p] = arr[r];
  // arr[r] = temp;

  int i = l+1;
  int j;
  for(j=l+1;j != r;j++){
    if(arr[j] <= arr[l]){
      temp = arr[i];
      arr[i] = arr[j];
      arr[j] = temp;
      i+=1;
    }
  }

  temp = arr[i];
  arr[i] = arr[l];
  arr[l] = temp;
  return i;
}

void quick_sort(int arr[],int l,int r){
  if(r <= l)
    return;
  int q = partition(arr,l,r);
  // printf("q=%d\n",q);
  for(int i = 0;i < n;i++)
    printf("%d ",arr[i]);
  printf("\n");
  quick_sort(arr,l,q-1);
  quick_sort(arr,q+1,r);
}

int main(){

  scanf("%d",&n);
  int arr[n];

  for(int i = 0;i < n;i++){
    scanf("%d",&arr[i]);
  }

  quick_sort(arr,0,n-1);

}

